#include "common.h"
#include "memory/cache.h"

/* Cache statistics */
static uint64_t cache_hit_count = 0;
static uint64_t cache_miss_count = 0;

void cache_hit() {
	cache_hit_count++;
}

void cache_miss() {
	cache_miss_count++;
}

void reset_cache_stats() {
	cache_hit_count = 0;
	cache_miss_count = 0;
}

void print_cache_stats() {
	uint64_t total = cache_hit_count + cache_miss_count;
	if (total > 0) {
		double hit_rate = (double)cache_hit_count / total * 100.0;
		printf("\n========== Cache Statistics ==========\n");
		printf("Cache Hits:   %llu\n", (unsigned long long)cache_hit_count);
		printf("Cache Misses: %llu\n", (unsigned long long)cache_miss_count);
		printf("Total Access: %llu\n", (unsigned long long)total);
		printf("Hit Rate:     %.2f%%\n", hit_rate);
		printf("======================================\n\n");
	}
}

